package model

import (
	"gitee.com/zhanglibin/gmall/conf"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"

	"fmt"
)

var Db *gorm.DB

func MysqlConnetInit() {
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8&parseTime=True&loc=Local&timeout=%s", conf.C.Mysql.User, conf.C.Mysql.Pass, conf.C.Mysql.Host, conf.C.Mysql.Port, conf.C.Mysql.Database, conf.C.Mysql.Timeout)

	fmt.Println("dsn=", dsn)
	db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		msg := fmt.Sprintf("mysql_init_error:%v\n", err)
		panic(msg)
	}

	Db = db
}
